<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title><?php echo C('WEB_TITLE');?></title>

		<link rel="stylesheet" type="text/css" href="/Public/css/common.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/js/layui/css/layui.css" media="all"/>

		<link rel="stylesheet" href="/Public/js/datepicker/datepicker.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/crm/css/index.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/crm/css/style.css"/>

		<link rel="stylesheet" href="<?php echo C('PC_ICON_HTTP');?>">

		<script type="text/javascript" >

			const moduleName = "<?php echo (MODULE_NAME); ?>";

		</script>

        <link rel="stylesheet" href="/Public/js/viewer/css/viewer.min.css">
		
		<link rel="stylesheet" type="text/css" href="/Public/js/select2/select2.css" media="all"/>

		<script type="text/javascript" src="/Public/js/jquery-1.9.1.min.js"></script>
		
		<script type="text/javascript" src="/Public/js/jquery-ui.min.js"></script>

		<script type="text/javascript" src="/Public/js/cookie/jquery.cookie.js"></script>

		<script type="text/javascript" src="/Public/js/lang/<?php echo (getStrToLower(cookie('think_language'))); ?>.js"></script>

		<script type="text/javascript" src="/Public/js/colorpicker.js"></script>

		<script type="text/javascript" src="/Public/js/layer/layer.js"></script>

		<script type="text/javascript" src="/Public/js/layui/layui.js"></script>

        <script type="text/javascript" src="/Public/js/feeldesk.js"></script>

        <script type="text/javascript" src="/Public/crm/js/index.js"></script>

        <script type="text/javascript" src="/Public/js/jquery.nicescroll.js"></script>

		<script type="text/javascript" src="/Public/js/clipboard.min.js"></script>

		<script type="text/javascript" src="/Public/js/select2/select2.min.js"></script>

		<script type="text/javascript" src="/Public/js/select2/jquery.core.js"></script>

	</head>

<body>

<script type="text/javascript" src="/Public/js/datepicker/datepicker.all.js"></script>

<script type="text/javascript" src="/Public/js/datepicker/moment.min.js"></script>

<script type="text/javascript" src="/Public/js/datepicker/datepicker.en.js"></script>

    <div class="fd-right-main">

        

    <div class="feeldesk-form pd0">

		<form action="<?php echo U('opportunity/edit',['id'=>encrypt($opportunity['opportunity_id'],'OPPORTUNITY'),'detailtype'=>encrypt($detailtype,'OPPORTUNITY')]);?>" class="layui-form" method="post" enctype="multipart/form-data">

        <div class="layui-tab">

            <ul class="layui-tab-title">

                <li class="layui-this"><?php echo L('MODIFY_OPPORTUNITY');?></li>

				<div class="form-submit">

					<a href="javascript:" class="layui-btn layui-btn-normal submitForm" data-no="<?php echo ($opportunity["opportunity_prefix"]); echo ($opportunity["opportunity_no"]); ?>"><?php echo l('SUBMIT');?></a>

					<?php if(!empty($detailtype)): ?><a href="javascript:history.go(-1);" class="layui-btn layui-btn-normal feelcrm-cancleBtn"><?php echo L('CANCEL');?></a><?php endif; ?>

				</div>

            </ul>

        </div>

        <div class="form-content pt50 wd50 fl border_r">
		<?php $t = 0; $ft = 0; $reg = 0; ?>

				 <div class="form-item">

				   <?php if(is_array($opportunityform)): $i = 0; $__LIST__ = $opportunityform;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><!-- 字段未设置查看范围或当前用户角色在查看范围内 -->
				   <?php if(!$vo['role_id'] || in_array($index['role_id'],explode(',',$vo['role_id']))): ?><!-- 字段未设置编辑权限或当前用户在编辑权限内 -->
				   <?php if(!$vo['member_id'] || in_array($index['member_id'],explode(',',$vo['member_id']))): if(($vo["form_name"]) != "stage"): ?><div class="layui-form-item">

                            <label class="layui-form-label">

                                <?php if(($vo["is_required"]) == "0"): ?><span class="red">*</span><?php endif; ?>

                                <?php echo ($vo["form_description"]); ?>

                            </label>

							<?php if(($vo["form_type"]) == "region"): $reg++; ?>

								<?php echo W('Region/getRegionEdit',['opportunity_form',$vo['form_name'],$reg,$opportunity]);?>

							<?php else: ?>

                            <div class="layui-input-inline">

                                <?php if(($vo["form_type"]) == "text"): ?><!-- 单行文本框 -->
                                    <input type="text" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" placeholder="" class="layui-input"><?php endif; ?>

								 <?php if(($vo["form_type"]) == "phone"): ?><!-- <?php echo L('CELL_PHONE');?> -->
                                    <input type="text" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && event.keyCode<48 || event.keyCode>57) event.returnValue=false" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" placeholder="" class="layui-input"><?php endif; ?>

								 <?php if(($vo["form_type"]) == "email"): ?><!-- <?php echo L('MAILBOX');?> -->
                                    <input type="text" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" placeholder="" class="layui-input"><?php endif; ?>

								 <?php if(($vo["form_type"]) == "number"): ?><!-- <?php echo L('DIGITAL');?> -->
                                    <input type="number" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && event.keyCode<48 || event.keyCode>57) event.returnValue=false" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" placeholder="" class="layui-input"><?php endif; ?>

								<?php if(($vo["form_type"]) == "decimal"): ?><!-- 小数 -->
                                    <input type="text" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" placeholder="" class="layui-input"><?php endif; ?>

                                <?php if(($vo["form_type"]) == "select"): ?><!-- 下拉菜单 -->
                                    <select name="opportunity_form[<?php echo ($vo["form_name"]); ?>]">

                                        <option value=""><?php echo ($vo["form_description"]); ?></option>

                                        <?php if(is_array($vo["option"])): foreach($vo["option"] as $key=>$op): ?><option value="<?php echo ($op); ?>" <?php if(($opportunity[$vo[form_name]]) == $op): ?>selected<?php endif; ?>><?php echo ($op); ?></option><?php endforeach; endif; ?>

                                    </select><?php endif; ?>
								
								<?php if(($vo["form_type"]) == "select_text"): $st++; ?>
									<!-- 下拉填写 -->
									<?php echo W('Update/selectTextForm',['opportunity',$vo,$st,$opportunity]); endif; ?>

                                <!-- 时间控件 -->
                                <?php if(($vo["form_type"]) == "date"): $ft++; ?>

                                    <input type='text' name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" class="layui-input cursor layui-form-time" id="form_time<?php echo $ft; ?>" placeholder="<?php echo L('SELECT_TIME');?>" ><?php endif; ?>

                                <?php if(($vo["form_type"]) == "checkbox"): ?><!-- 复选框 -->
                                    <?php if(is_array($vo["option"])): $i = 0; $__LIST__ = $vo["option"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$op): $mod = ($i % 2 );++$i;?><input type="checkbox" name="opportunity_form[<?php echo ($vo["form_name"]); ?>][]" <?php if(in_array(($op), is_array($opportunity[$vo[form_name]])?$opportunity[$vo[form_name]]:explode(',',$opportunity[$vo[form_name]]))): ?>checked<?php endif; ?> lay-skin="primary" title="<?php echo ($op); ?>" value="<?php echo ($op); ?>"><?php endforeach; endif; else: echo "" ;endif; endif; ?>

                                <?php if(($vo["form_type"]) == "radio"): ?><!-- 单选框-->
                                    <?php if(is_array($vo["option"])): $i = 0; $__LIST__ = $vo["option"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$op): $mod = ($i % 2 );++$i;?><input type="radio" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" <?php if(($opportunity[$vo[form_name]]) == $op): ?>checked<?php endif; ?> value="<?php echo ($op); ?>" title="<?php echo ($op); ?>"><?php endforeach; endif; else: echo "" ;endif; endif; ?>

                                <!-- 文本域 -->
                                <?php if(($vo["form_type"]) == "textarea"): $t++ ?>

                                    <textarea class="layui-textarea layui-hide ticket-textarea" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" id="ticketEditor<?php echo $t; ?>"><?php echo ($opportunity[$vo['form_name']]); ?></textarea><?php endif; ?>

                            </div><?php endif; ?>

                            <?php if(!empty($vo["form_explain"])): ?><i class="layui-icon layui-icon-about intro-icon" data-note="<?php echo ($vo["form_explain"]); ?>"></i><?php endif; ?>

                        </div>

					   <?php else: ?>

						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" /><?php endif; ?>

				   <?php else: ?>

					   <?php if(($vo["form_type"]) == "region"): ?><input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultCountry]" value="<?php echo ($opportunity[$vo['form_name']]['defaultCountry']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultProv]" value="<?php echo ($opportunity[$vo['form_name']]['defaultProv']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultCity]" value="<?php echo ($opportunity[$vo['form_name']]['defaultCity']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultArea]" value="<?php echo ($opportunity[$vo['form_name']]['defaultArea']); ?>" >

						   <?php else: ?>

						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" ><?php endif; endif; ?>

				   <?php else: ?>

					   <?php if(($vo["form_type"]) == "region"): ?><input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultCountry]" value="<?php echo ($opportunity[$vo['form_name']]['defaultCountry']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultProv]" value="<?php echo ($opportunity[$vo['form_name']]['defaultProv']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultCity]" value="<?php echo ($opportunity[$vo['form_name']]['defaultCity']); ?>" >
						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>_defaultArea]" value="<?php echo ($opportunity[$vo['form_name']]['defaultArea']); ?>" >

						   <?php else: ?>

						   <input type="hidden" name="opportunity_form[<?php echo ($vo["form_name"]); ?>]" value="<?php echo ($opportunity[$vo['form_name']]); ?>" ><?php endif; endif; endforeach; endif; else: echo "" ;endif; ?>

				</div>

        </div>

		<div class="form-content wd50 fl">

			<div class="form-item pb25">

				<div class="list-header clearfix">

					<div class="header-left">

						<a href="javascript:" class="item-deleteBtn choosepro"><i class="iconfont icon-xinzeng"></i><?php echo L('ADD_PRODUCT');?></a>

					</div>

				</div>

				 <div class="item-list">

					<table class="layui-table" lay-skin="line">

						<thead>

							<tr>

								<th><?php echo L('PRODUCT_NUM');?></th><th><?php echo L('PRODUCT_NAME');?></th><th><?php echo L('PRODUCT_CATEGORY');?></th><th><?php echo L('PRICE');?></th>

							</tr>

						</thead>

						<tbody id="chooseProList">

							<?php $proKey = 1; ?>

							<?php if(is_array($opportunityPro)): $i = 0; $__LIST__ = $opportunityPro;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr data-id="<?php echo ($vo['product_id']); ?>" class="checkedPro">

									<input type="hidden" name="opportunityPro[<?php echo ($key); ?>][product_id]" value="<?php echo encrypt($vo['product_id'],'PRODUCT');?>" />

									<td><?php echo ($vo["detail"]["product_num"]); ?></td>

									<td><?php echo ($vo["detail"]["name"]); ?></td>

									<td><?php echo ($vo["type_name"]); ?></td>

									<td><?php echo number_format($vo['detail']['list_price'],2);?></td>

								</tr>

								<?php $proKey ++; endforeach; endif; else: echo "" ;endif; ?>

						</tbody>

					</table>

				</div>

            </div>

		</div>

		<div class="clear"></div>

		</form>

    </div>

	<div class="hidden hg100" id="productlist">

		<div class="feeldesk-form pd0 feelcrm-form">

			<div class="layui-tab">

				<ul class="layui-tab-title">

					<li class="tab-title-name"><?php echo L('ADD_PRODUCT');?></li>

					<li class="tab-title-btn">

						<a href="javascript:chooseProduct()" class="layui-btn layui-btn-normal titleSubmit"><?php echo l('SUBMIT');?></a>

						<a href="javascript:closeChoosepro();" class="layui-btn layui-btn-normal titleCancel"><?php echo l('CANCEL');?></a>

						<div class="clear"></div>

					</li>

					<form action="" class="fr searchProForm" method="get">

						<div class="compact-search">

							<i class="iconfont icon-search"></i>

							<input type="text" name="proKeyword" value="" placeholder=""/>

							<input type="text" class="hidden" name="" value="" placeholder=""/>

							<a href="javascript:" class="searchProBtn"><?php echo L('SEARCH');?></a>

						</div>

					</form>

					<div class="clear"></div>

				</ul>

			</div>

		</div>

		<div class="product-tree fl">

			<div class="protree protree-1 protree-default">

				<?php if(is_array($product_type_h)): foreach($product_type_h as $key=>$vo): echo ($vo); endforeach; endif; ?>

			</div>

        </div>

		<div class="item-list">

			<table class="layui-table" lay-skin="line">

				<thead>

					<tr>

						<th></th><th><?php echo L('PRODUCT_CATEGORY');?></th><th><?php echo L('IMAGES');?></th><th><?php echo L('PRODUCT_NAME');?></th><th><?php echo L('PRODUCT_NUM');?></th><th><?php echo L('PRICE');?></th>

					</tr>

				</thead>

				<tbody id="product-detail">

					<?php if(empty($product)): ?><tr class="nodata center">

							<td colspan="11">

								<p><i class="iconfont icon-nothing fts20"></i></p>

								<p><?php echo L('NO_DATA');?></p>

							</td>

						</tr>

					<?php else: ?>

						<?php if(is_array($product)): $i = 0; $__LIST__ = $product;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>

								<td><input type="checkbox" value="<?php echo ($vo["product_id"]); ?>" <?php if(($vo["opportunity_pro"]) == "1"): ?>checked<?php endif; ?> name="product[]" /></td>

								<td><?php echo ($vo["type_name"]); ?></td>

								<td><img src="<?php echo ((isset($vo["product_img"]) && ($vo["product_img"] !== ""))?($vo["product_img"]):'/Public/crm/img/default_pro.png'); ?>" width="40" height="40" /></td>

								<td><?php echo ($vo["name"]); ?></td>

								<td><?php echo ($vo["product_num"]); ?></td>

								<td><?php echo ($vo["list_price"]); ?></td>

							</tr><?php endforeach; endif; else: echo "" ;endif; endif; ?>

				</tbody>

			</table>

			<div class="right-list-page clearfix"><div class="feeldesk-page"><?php echo ($page); ?></div></div>

		</div>

	</div>

    <script type="text/javascript" src="/Public/js/submitform.js"></script>
<script type="text/javascript">
	
	layui.use('form',function()
	{
		var form = layui.form;
		
		form.render('checkbox');
		
		form.render('radio');
		
		form.render('select');

	})
	
</script>


    <script>

		var proKey = '<?php echo ($proKey); ?>';

		$(function(){
			$('.choosepro').click(function(){

				var index = layer.open({
				  type: 1,
				  title: false,
				  scrollbar:false,
				  area: ['80%','600px'],
				  closeBtn:0,
				  content: $('#productlist')
				});

			})

			$('.feeldesk-page a').click(function(){

				pageclick(this);

				return false;
			})

			$('.protree-node a').click(function(){

				pageclick(this);

				$('.product-tree li a').css('background','none');

				$(this).css('background','#e1f6ff');

				return false;

			})

			$('input[name="product[]"]').click(function(){

				var val = $(this).val();

				if(!$(this).is(':checked'))
				{
					$('.checkedPro[data-id="'+val+'"]').remove();
				}

			})

		})

		function pageclick(obj)
		{
			var href = $(obj).attr('href');

			var ajaxhref = href.replace('/Opportunity/edit', '/AjaxRequest/getProductList');

			var checkedPro = [];

			$.each($('.checkedPro'),function(){

				checkedPro.push($(this).data('id'));

            });

			var keyword = $('input[name="proKeyword"]').val();

			$.ajax({
					url:ajaxhref,
					type:'POST',
					data:{'checkedPro':checkedPro,'keyword':keyword},
					async: false,
					datatype:'json',
					success:function(data)
					{
						//console.log(11);return false;
						$('#product-detail').html(data.html);

						$('.feeldesk-page').html(data.page);

						$('.feeldesk-page a').click(function(){

							pageclick(this);

							return false;
						})

						$('input[name="product[]"]').click(function(){

							var val = $(this).val();

							if(!$(this).is(':checked'))
							{
								$('.checkedPro[data-id="'+val+'"]').remove();
							}

						})
					},
					error:function()
					{
					   layer.msg("<?php echo L('FAILED_TO_GET_PRODUCT');?>");
					}
			 });
		}

		$('.searchProBtn').unbind('click').bind('click',function(){

			searchPro();
		});

		function searchPro()
		{
			var checkedPro = [];

			$.each($('.checkedPro'),function(){

				checkedPro.push($(this).data('id'));

			});

			var keyword = $('input[name="proKeyword"]').val();

			var ajaxhref = "<?php echo U('AjaxRequest/getProductList');?>";

			$.ajax({
				url:ajaxhref,
				type:'post',
				data:{'checkedPro':checkedPro,'keyword':keyword},
				async: false,
				datatype:'json',
				success:function(data)
				{
					$('#product-detail').html(data.html);

					$('#productlist .feeldesk-page').html(data.page);

					$('#productlist .feeldesk-page a').click(function(){

						pageclick(this);

						return false;
					});

					$('input[name="product[]"]').click(function(){

						var val = $(this).val();

						if(!$(this).is(':checked'))
						{
							$('.checkedPro[data-id="'+val+'"]').remove();
						}

					});
				},
				error:function()
				{
					layer.msg("<?php echo L('FAILED_TO_GET_PRODUCT');?>");
				}
			});

			$('.product-tree li a').css('background','none');

			return false;
		}

		function closeChoosepro()
		{
			layer.close(layer.index);
		}

		function chooseProduct()
		{
			var product = [];

			var checkedPro = [];

			$.each($('input[name="product[]"]:checked'),function(){

				product.push($(this).val());

            });

			$.each($('.checkedPro'),function(){

				checkedPro.push($(this).data('id'));

            });

			$.ajax({
					url:"<?php echo U('AjaxRequest/addOpportunityProduct');?>",
					type:'POST',
					data:{'product':product,'checkedPro':checkedPro,'proKey':proKey},
					async: false,
					datatype:'json',
					success:function(data)
					{
						$('#chooseProList').append(data.html);

						proKey = data.proKey;
					},
					error:function()
					{
					   layer.msg("<?php echo L('FAILED_TO_ADD_PRODUCT');?>");
					}
			});

			layer.close(layer.index);
		}

	</script>



    </div>

    <script type="text/javascript">

        layer.ready(function()
        {
            layer.photos({
                photos: '.textareaImg',
                shift: 5,
                shade: [0.8, 'rgba(0,0,0,.8)']
            });

        })

    </script>

    <script>

        //客户端
        /*if ( navigator.userAgent.toLowerCase().indexOf('electron/') > -1)
        {
            top.setIframe(document);
        }*/
    </script>

    </body>

</html>